package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Param
 * @return
 */
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
//条件化注入，有minio，且下面有username则生效，没有则不生效
@ConditionalOnProperty(prefix = "minio",name = "username")
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder().endpoint(minioProperties.getEndPoint())
                .credentials(minioProperties.getUsername(),minioProperties.getPassword())
                .build();
    }
}
